package com.jqk.shoporder.controller;

import com.jqk.shoporder.bean.Order;
import com.jqk.shoporder.bean.TblOrderEvent;
import com.jqk.shoporder.feign.ProductService;
import com.jqk.shoporder.service.OrderService;
import com.jqk.shoporder.service.TblOrderEventService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:JiangQiKun
 * @Date:2022/03/16 12:14 AM
 * Description:
 * com.jqk.shoporder.controllerMessageTrancastionController
 */
@RestController
@Slf4j
public class MessageTrancastionController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private OrderService orderService;

    @Autowired
    private TblOrderEventService tblOrderEventService;

    @GetMapping("/save-mesage")
    @Transactional(rollbackFor = Exception.class)
    public String saveMessage(@PathVariable("pid") Integer pid) {
        Order order = new Order();
        order.setUid(1);
        order.setPid(pid);
        order.setUserName("下单用户");
        //1：保存订单
        orderService.save(order);
        //2:保存本地事务表
        TblOrderEvent event=new TblOrderEvent();
        tblOrderEventService.save(event);
        return "success";
    }


}
